<?php
class Assignment extends AppModel {
	var $name = 'Assignment';
	var $primaryKey = 'assignment_id';

	var $validate = array(
					'assignment_id' => VALID_NUMBER,
					'user_id' => VALID_NUMBER,
					'apartment_id' => VALID_NUMBER,
	);

	var $belongsTo = array(
					'User' =>
					array('className' => 'User',
								'foreignKey' => 'user_id'),
					'Apartment' =>
					array('className' => 'Apartment',
								'foreignKey' => 'apartment_id')
					);

	function findUsers($semesterId, $apartmentId) {
		$users = $this->query("SELECT User.user_id, User.firstName, User.lastName from 
									users as User, 
									assignments as assign,
									apartments as apts
									where apts.apartment_id = assign.apartment_id AND
									assign.user_id = User.user_id AND
									apts.apartment_id = '$apartmentId' AND
									apts.semester_id = '$semesterId'
									ORDER BY User.lastName, User.firstName");
		return $users;
	}
}
?>
